package pgdgit01;

import java.util.ArrayList;

/**
 * Models the borrower of a <code>Publication</code>.
 * @author PGDSWD class, October 2013
 */
public class Borrower {
    static int count = 1;
    String name;
    String id;
    String address;
    String telephone;
    String email;
    ArrayList<Publication> borrowedItems;
    
    /**
     * Constructs a library item Borrower with the given ID and full name.
     * @param name - the borrower's full name
     * @param id - the borrower's ID number
     */
    public Borrower(String name) {
        this.name = name;
        this.id = String.valueOf(count++);
    }
    /**
     * Constructs an instance of Borrower from the given data.
     * @param name - the borrower's full name
     * @param id - the borrower's ID number
     * @param address - the borrower's full address
     * @param telephone - the borrower's telephone number
     * @param email - the borrower's e-mail address
     */
    public Borrower(String name,  String address, String telephone, String email) {
        this.name = name;
        this.id = String.valueOf(count++);
        this.address = address;
        this.telephone = telephone;
        this.email = email;
        borrowedItems = new ArrayList<>(); 
    }
    /**
     * Getter for the full name of the Borrower.
     * @return the borrower's full name
     */
    public String getName() {
        return name;
    }
  /**
   * Getter for the ID number of the Borrower.
   * @return the borrower's id.
   */
    public String getId() {
        return id;
    }
    /**
     * Getter for the address of the Borrower.
     * @return the borrower's address.
     */
    public String getAddress() {
        return address;
    }
    /**
     * Setter for the address of the Borrower.
     * @param address - the new address. 
     */
    public void setAddress(String address) {
        this.address = address;
    }
    /**
     * Getter for the telephone number of the Borrower.
     * @return the borrower's phone number
     */
    public String getTelephone() {
        return telephone;
    }
    /**
     * Setter for the telephone number of the Borrower.
     * @param telephone - the new telephone number.
     */
    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }
    /**
     * Getter for the e-mail address of the Borrower.
     * @return the borrower's e-mail address.
     */
    public String getEmail() {
        return email;
    }
    /**
     * Setter for the e-mail address of the Borrower.
     * @param email - the new e-mail address. 
     */
    public void setEmail(String email) {
        this.email = email;
    }
    /**
     * Getter for the list of Publications checked out by the Borrower.
     * @return the array list of borrowed items.
     */
    public ArrayList<Publication> getBorrowedItems() {
        return borrowedItems;
    }
    /**
     * Getter for a formatted string of the full personal details of the Borrower, e.g.
     * "ID: 1234567890123\nName: Jane Doe \nTel.: 1234567890  E-mail: jd@hers.org".
     * @return the borrower's full details
     */
    public String getFullDetails(){
        
        return "ID: "+ getId()+ "\nName :" + getName() + " Address: " + getAddress()
                +  "\nTelephone : " + getTelephone() + " Email : "+getEmail();
    }
    /**
     * Checks out a Publication against the Borrower.
     * @param p the item to be checked out
     * @param checkoutDate the borrowing date
     * @param returnDate the return date.
     */
    public void checkoutItem(Publication p,String checkoutDate,String returnDate){
        
        p.setCheckoutDate(checkoutDate);
        p.setReturnDate(returnDate);
        borrowedItems.add(p);  
    }
    /**
     * Returns a borrowed item to the library.
     * @param p the item to return
     */
    public void returnItem(Publication p){
        
        borrowedItems.remove(p);
     
      
    }
}
